<template>
	<view class="myxuqiu">
		<headertop title="我的需求" str1="oridei" :back1="back1"></headertop>
		<image src="https://jingwei.xunfuzhifuzaixian.com/static/images/Group 11889@2x.png" class="myxuqiuback"
			mode="widthFix"></image>
		<view :style="{'margin-top':statusBarHeight+'px','height':barHeight+'px'}"></view>
		<view class="bottomContent">
			<view class="centerbb">
				<view class="inputbox">
					<view class="labletitle">
						联系人：
					</view>
					<input type="text" v-model="query['username']" placeholder="请输入联系人" />
				</view>
				<view class="inputbox">
					<view class="labletitle">
						联系方式：
					</view>
					<input type="text" v-model="query['phone']" placeholder="请输入联系方式" />
				</view>
				<view class="textsinput">
					<view class="centersm">
						<view class="xqtitle">
							需求说明：
						</view>
						<textarea name="" v-model="query['shuoming']" placeholder="请输入需求说明" id="" cols="30"
							rows="10"></textarea>
					</view>
				</view>
			</view>
		</view>
		<view class="fixedbox">
			<view class="btn" @click="xqtj">
				确认添加
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted,
		reactive,
	} from 'vue'
	import headertop from '@/components/header.vue'
	const barHeight = ref('')

	const statusBarHeight = ref('')
	import {
		$api
	} from '../../ulm';
	const query = reactive({
		username: '',
		phone: '',
		shuoming: ''
	})
	onMounted(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight
		const {
			top,
			height
		} = wx.getMenuButtonBoundingClientRect();
		barHeight.value = height ? height + (top - statusBarHeight.value) * 2 : 38;
	})
	async function xqtj() {
		for (var i in query) {
			if (!query[i]) {
				uni.showToast({
					title: '请补充好内容提交',
					icon: 'none'
				})
				return
			}
		}
		const phoneRegex = /^1[3-9]\d{9}$/;
		if (!phoneRegex.test(query['phone'])) {
			uni.showToast({
				title: '请输入正确联系方式',
				icon: 'none'
			})
			return
		}

		const res = await $api.xuqiuadd(query)
		if (res.code == 1) {
			uni.navigateBack()
			setTimeout(() => {
				uni.showToast({
					title: '添加成功',
					icon: 'none'
				})
			}, 500)
		} else {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
		}
	}
</script>

<style lang="scss">
	.myxuqiu {
		width: 100%;
		overflow: hidden;
		position: relative;

		.myxuqiuback {
			width: 100%;
			z-index: -1;
			position: absolute;
		}

		.fixedbox {
			width: 100%;
			height: 186rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -4rpx 10rpx 0rpx rgba(0, 0, 0, 0.06);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			position: fixed;
			bottom: 0%;

			.btn {
				width: 686rpx;
				height: 82rpx;
				background: #13A2E6;
				border-radius: 12rpx 12rpx 12rpx 12rpx;
				text-align: center;
				line-height: 82rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #FFFFFF;
				margin: auto;
				margin-top: 24rpx;
			}
		}

		.bottomContent {
			width: 100%;
			background: #FFFFFF;
			box-shadow: 0rpx -4rpx 13rpx 0rpx rgba(157, 219, 255, 0.56);
			border-radius: 48rpx 48rpx 0rpx 0rpx;
			overflow: hidden;
			margin-top: 246rpx;

			.centerbb {
				width: 686rpx;
				margin: auto;
				margin-top: 32rpx;
				overflow: hidden;

				.textsinput {
					width: 100%;
					height: 266rpx;
					background: #F7F8FA;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					overflow: hidden;

					.centersm {
						width: 630rpx;
						margin: auto;
						margin-top: 24rpx;
						overflow: hidden;

						.xqtitle {
							width: 100%;
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 32rpx;
							color: #1D2129;
						}

						textarea {
							width: 630rpx;
							font-size: 32rpx;
							margin-top: 16rpx;
							height: 160rpx;
						}
					}
				}

				.inputbox {
					height: 92rpx;
					background: #F7F8FA;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					width: 100%;
					margin-bottom: 24rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.labletitle {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						width: 250rpx;
						white-space: nowrap;
						font-size: 32rpx;
						color: #1D2129;
						margin-left: 28rpx;
					}

					input {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #86909C;
						margin-right: 28rpx;
						text-align: right;
					}
				}
			}
		}
	}
</style>